﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TZReport_Model.DB;
using TZReport_Model.DBModel;
using TZReport_Model.RemoteModel;
using TZReport_Service.Config;
using TZReport_Util.Basic;
using TZReport_Util.Extendsions;
using TZReport_Util.Model;
using TZReport_Util.Util;
using TZRerport_Dal.Dal;
using TZRerport_Dal.IDal;
using System.IO;
using TZReport_Util.Log;
using System.Net;
using System.Reflection;

namespace TZReport_Service.TZService
{
    public class TZReportService
    {
        private static readonly LogHelper LogHelper = new LogHelper(typeof(TZReportService));
        private WebUtils webUtils = new WebUtils();
        private TZ_Report_RecordDal TZ_Report_RecordDal = new TZ_Report_RecordDal();
        private TZ_Report_Record_RetryDal TZ_Report_Record_RetryDal = new TZ_Report_Record_RetryDal();
        private const string _token = "tzdqtjToken";
        private const string formatTime = "yyyy-MM-dd HH:mm:ss";
        ISql _iSql = null;

        public TZReportService(ISql iSql)
        {
            _iSql = iSql;
        }

        public ResultInfo RetryReportUpload(string tjh)
        {
            TZ_Report_Record record = TZ_Report_RecordDal.Get(a => a.physical_no == tjh).FirstOrDefault();
            if (record == null)
                return CodeStatus.success.GetStatus();

            TZ_Report_Record_Retry retry = GetTZReportRecordRetry(record);
            bool b = TZ_Report_Record_RetryDal.RemoveReportRecord(retry, record);
            if (!b)
                return CodeStatus.error_301.GetStatus("上传数据转移失败");

            return CodeStatus.success.GetStatus();
        }

        private TZ_Report_Record_Retry GetTZReportRecordRetry(TZ_Report_Record record)
        {
            TZ_Report_Record_Retry retry = new TZ_Report_Record_Retry();
            Type retryType = retry.GetType();
            PropertyInfo[] retryProps = retryType.GetProperties();
            Type recordType = record.GetType();
            PropertyInfo[] recordProps = recordType.GetProperties();

            foreach (PropertyInfo retryP in retryProps)
            {
                if (retryP.Name == "id")
                    retryP.SetValue(retry, Guid.NewGuid());
                else if (retryP.Name == "ins_time")
                    retryP.SetValue(retry, DateTime.Now);
                else
                {
                    PropertyInfo prop = recordProps.Where(a => a.Name == retryP.Name).FirstOrDefault();
                    if (prop != null)
                    {
                        object value = prop.GetValue(record);
                        retryP.SetValue(retry, value);
                    }
                }
            }

            return retry;
        }

        public ResultInfo EditFileName()
        {
            string dirPath = HospitalConfigManager.absPath;
            string[] filePaths = Directory.GetFiles(dirPath);
            List<string> list = new List<string>();
            foreach (string filePath in filePaths)
            {
                string fileName = filePath.Replace(dirPath, "");
                string tjhPDF = fileName.Substring(0, 8) + ".pdf";
                string newPath = dirPath + tjhPDF;
                File.Move(filePath, newPath);

                File.Delete(fileName);
            }

            ResultInfo res = CodeStatus.success.GetStatus();
            res.data = new { list = list };

            return res;
        }

        public ResultInfo EditRecordPDF()
        {
            string dirPath = HospitalConfigManager.absPath;
            string[] filePaths = Directory.GetFiles(dirPath);
            List<string> list = new List<string>();
            foreach (string filePath in filePaths)
            {
                string fileName = filePath.Replace(dirPath, "").Replace(".pdf", "");
                list.Add(fileName);
            }

            ResultInfo res = CodeStatus.success.GetStatus();

            List<object> listResult = new List<object>();
            List<TZ_Report_Record> listRescord = TZ_Report_RecordDal.Get(a => list.Contains(a.physical_no) && a.is_pdf == PDFEnum.init.GetHashCode()).ToList();
            foreach (TZ_Report_Record record in listRescord)
            {
                record.is_pdf = PDFEnum.success.GetHashCode();
                if (TZ_Report_RecordDal.Up(record))
                {
                    object obj = new { tjh = record.physical_no, status = "成功" };
                    LogHelper.Info(JsonXmlUtils.SerializeObject(obj));
                    listResult.Add(obj);
                }
                else
                {
                    object obj = new { tjh = record.physical_no, status = "失败" };
                    LogHelper.Info(JsonXmlUtils.SerializeObject(obj));
                    listResult.Add(obj);
                }
            }

            res.data = listResult;

            return res;
        }

        public ResultInfo liShiSJ(string startDate, string endDate, string jiGouDM)
        {
            if (string.IsNullOrEmpty(startDate))
                return CodeStatus.error_201.GetStatus($"{startDate}为空");
            if (string.IsNullOrEmpty(endDate))
                return CodeStatus.error_201.GetStatus($"{endDate}为空");
            if (string.IsNullOrEmpty(jiGouDM))
                return CodeStatus.error_201.GetStatus($"{jiGouDM}为空");

            DateTime dt;
            if (!DateTime.TryParse(startDate, out dt))
                return CodeStatus.error_201.GetStatus($"{startDate}格式不正确");

            if (!DateTime.TryParse(endDate, out dt))
                return CodeStatus.error_201.GetStatus($"{endDate}格式不正确");

            List<string> listTiJianH = _iSql.GetTiJianBHList(startDate, endDate, EnumManager.success_pdf_code);
            List<object> listResult = new List<object>();
            foreach (string tjh in listTiJianH)
            {
                listResult.Add(new
                {
                    jiGouDM = HospitalConfigManager.hospitalBM,
                    tiJianBH = tjh
                });
            }

            ResultInfo res = new ResultInfo();
            res.code = 1;
            res.msg = "成功。";
            res.data = listResult;

            return res;
        }

        public ResultInfo BaoGaoBC(List<BaoGaoBCParamter> listParamter)
        {
            if (listParamter == null || listParamter.Count == 0)
                return CodeStatus.error_201.GetStatus("参数为空");

            List<string> listTJH = listParamter.Select(a => a.tiJianBH).ToList();

            List<TZ_Report_Record> listRecord = TZ_Report_RecordDal.GetAsNoTracking(a => listTJH.Contains(a.physical_no)).ToList();
            if (listRecord == null || listRecord.Count == 0)
                return CodeStatus.error_202.GetStatus("未查到补传数据");
            ResultInfo res = CodeStatus.success.GetStatus();
            foreach (TZ_Report_Record record in listRecord)
            {
                // 如果pdf传成功就不用传了
                if (record.status == EnumManager.success_pdf_code)
                {
                    res = UpLoad(record);
                    if (res.code != CodeStatus.success.GetHashCode())
                        return res;

                    res = PDF(record);
                    if (res.code != CodeStatus.success.GetHashCode())
                        return res;
                    //continue;
                }

                // 登记信息成功，就补传pdf
                if (record.status == EnumManager.success_dengji_code)
                {
                    res = PDF(record);
                    if (res.code != CodeStatus.success.GetHashCode())
                        return res;
                }

                // 初始化或者登记信息上传失败，就登记信息和pdf都一起传
                if (record.status == EnumManager.init_code || record.status == EnumManager.fail_upload_code)
                {
                    res = UpLoad(record);
                    if (res.code != CodeStatus.success.GetHashCode())
                        return res;

                    res = PDF(record);
                    if (res.code != CodeStatus.success.GetHashCode())
                        return res;
                }

                // pdf上传失败，补传pdf
                if (record.status == EnumManager.fail_pdf_code)
                {
                    res = PDF(record);
                    if (res.code != CodeStatus.success.GetHashCode())
                        return res;
                }
            }

            res = new ResultInfo();
            res.code = 1;
            res.msg = "成功。";

            return res;
        }

        /// <summary>
        /// 数据准备
        /// </summary>
        /// <returns></returns>
        public ResultInfo InitRecord()
        {
            List<TiJianBModel> listTJBModel = _iSql.GetTiJianBModelList();
            return InitRecord(listTJBModel);
        }

        public ResultInfo InitRecord(int num)
        {
            List<TiJianBModel> listTJBModel = _iSql.GetTiJianBModelList(num);
            return InitRecord(listTJBModel);
        }

        public ResultInfo AutoUpLoad()
        {
            int pdfSucccess = PDFEnum.success.GetHashCode();
            int[] statuses = new int[]
            {
                EnumManager.init_code,
                EnumManager.success_dengji_code
            };

            TZ_Report_Record record = TZ_Report_RecordDal.GetAsNoTracking(a =>
            statuses.Contains(a.status)
            && a.is_pdf == pdfSucccess).OrderByDescending(a => a.physical_serial_no).ThenByDescending(a => a.report_date).FirstOrDefault();
            if (record == null)
                return CodeStatus.error_202.GetStatus("无待传数据");

            ResultInfo res = UpLoad(record);
            return res;
        }

        public ResultInfo ManualUpload(string tjh)
        {
            TZ_Report_Record record = TZ_Report_RecordDal.GetAsNoTracking(a => a.physical_no == tjh).FirstOrDefault();
            if (record == null)
                return CodeStatus.error_202.GetStatus("无上传数据");

            return UpLoad(record);
        }

        public ResultInfo ManualDengJiUpLoad(string tjh)
        {
            TZ_Report_Record record = TZ_Report_RecordDal.GetAsNoTracking(a => a.physical_no == tjh).FirstOrDefault();
            if (record == null)
                return CodeStatus.error_202.GetStatus("无上传数据");
            return DengJi(record);
        }

        public ResultInfo ManualPDFUpLoad(string tjh)
        {
            TZ_Report_Record record = TZ_Report_RecordDal.GetAsNoTracking(a => a.physical_no == tjh).FirstOrDefault();
            if (record == null)
                return CodeStatus.error_202.GetStatus("无上传数据");
            return PDF(record);
        }

        /// <summary>
        /// 信息登记
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public ResultInfo DengJi(TZ_Report_Record record)
        {
            string interfaceUrl = "/credit/tijian/dengji";
            DengJiModel model = GetDengJiModel(record);
            string paramter = JsonXmlUtils.SerializeObject(model);
            ResultInfo res = Remote(record.physical_no, interfaceUrl, paramter);
            if (res.code != CodeStatus.success.GetHashCode())
            {
                record.status = EnumManager.fail_upload_code;
                record.status_name = EnumManager.fail_upload_name;
                record.fail_msg = JsonXmlUtils.SerializeObject(res);
                record.operate_time = DateTime.Now;
            }
            else
            {
                record.status = EnumManager.success_dengji_code;
                record.status_name = EnumManager.success_dengji_name;
                record.operate_time = DateTime.Now;
            }

            if (!TZ_Report_RecordDal.Up(record))
                return CodeStatus.error_301.GetStatus("修改失败");

            return CodeStatus.success.GetStatus();
        }

        public ResultInfo GetPDFBase64(string tjh)
        {
            TZ_Report_Record record = TZ_Report_RecordDal.GetAsNoTracking(a => a.physical_no == tjh).FirstOrDefault();
            if (record == null)
                return CodeStatus.error_202.GetStatus("无记录");
            string failMsg = string.Empty;
            byte[] bys = webUtils.GetBytesByPDF(record.pdf_path, out failMsg);
            if (!string.IsNullOrEmpty(failMsg))
                return CodeStatus.error_223.GetStatus($"tjh:{tjh},failMsg:{failMsg}");

            ResultInfo res = CodeStatus.success.GetStatus();
            res.data = Convert.ToBase64String(bys);
            return res;
        }

        public ResultInfo UpReplaceEmpty()
        {
            int fail_info_code = EnumManager.fail_info_code;
            List<TZ_Report_Record> listReportRecord = TZ_Report_RecordDal.Get(a => a.status == fail_info_code).ToList();
            List<object> listResult = new List<object>();
            if (listReportRecord != null && listReportRecord.Count > 0)
            {
                int initCode = EnumManager.init_code;
                listReportRecord.ForEach(a =>
                {
                    a.status = initCode;
                    a.phone = StringUtils.ReplaceEmpty(a.phone);
                    a.idcard = StringUtils.ReplaceEmpty(a.idcard);
                    a.name = StringUtils.ReplaceEmpty(a.name);
                });

                foreach (TZ_Report_Record reportRecord in listReportRecord)
                {
                    if (!TZ_Report_RecordDal.Up(reportRecord))
                    {
                        listResult.Add(new
                        {
                            tjlsh = reportRecord.physical_serial_no,
                            idcard = reportRecord.idcard,
                            status = "失败",
                        });
                    }
                    else
                    {
                        listResult.Add(new
                        {
                            tjlsh = reportRecord.physical_serial_no,
                            idcard = reportRecord.idcard,
                            status = "成功",
                        });
                    }
                }
            }

            ResultInfo res = CodeStatus.success.GetStatus();
            res.data = new { list = listResult };
            return res;
        }

        /// <summary>
        /// pdf上传
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public ResultInfo PDF(TZ_Report_Record record)
        {
            string interfaceUrl = "/credit/tijian/baoGaoPDFSC";
            string failMsg = string.Empty;
            byte[] bys = webUtils.GetBytesByPDF(record.pdf_path, out failMsg);
            if (!string.IsNullOrEmpty(failMsg))
            {
                record.status = EnumManager.fail_info_code;
                record.status_name = EnumManager.fail_info_name;
                record.fail_msg = $"pdf不存在(0):{failMsg}";
                record.is_pdf = PDFEnum.init.GetHashCode();
                if (!TZ_Report_RecordDal.Up(record))
                    return CodeStatus.error_301.GetStatus("pdf不存在修改失败");
                else
                    return CodeStatus.error_223.GetStatus($"{record.fail_msg}");
            }

            string base64PDF = Convert.ToBase64String(bys);
            PDFModel model = GetPDFModel(base64PDF, record);
            string paramter = JsonXmlUtils.SerializeObject(model);

            ResultInfo res = Remote(record.physical_no, interfaceUrl, paramter);

            if (res.code != CodeStatus.success.GetHashCode())
            {
                record.status = EnumManager.fail_pdf_code;
                record.status_name = EnumManager.fail_pdf_name;
                record.fail_msg = JsonXmlUtils.SerializeObject(res);
                record.operate_time = DateTime.Now;
            }
            else
            {
                record.status = EnumManager.success_pdf_code;
                record.status_name = EnumManager.success_pdf_name;
                record.fail_msg = null;
                record.operate_time = DateTime.Now;
            }

            if (!TZ_Report_RecordDal.Up(record))
                return CodeStatus.error_301.GetStatus("修改失败");
            res = CodeStatus.success.GetStatus();
            res.data = base64PDF;
            return res;

        }

        private ResultInfo InitRecord(List<TiJianBModel> listTJBModel)
        {
            if (listTJBModel == null || listTJBModel.Count == 0)
                return CodeStatus.success.GetStatus();

            List<TZ_Report_Record> listRecord = ConvertReportRecord(listTJBModel);

            // 如果已经包含了就不要插入了
            List<string> listTJH = TZ_Report_RecordDal.GetAsNoTracking(a => true).Select(a => a.physical_no).ToList();
            // 去除已经存在的体检号
            listRecord.RemoveAll(a => listTJH.Contains(a.physical_no));

            bool b = TZ_Report_RecordDal.InsReportRecord(listRecord);
            if (!b)
                return CodeStatus.error_301.GetStatus("添加失败");

            return CodeStatus.success.GetStatus();
        }

        /// <summary>
        /// 获取上传pdf的
        /// </summary>
        /// <param name="base64PDF"></param>
        /// <param name="record"></param>
        /// <returns></returns>
        private PDFModel GetPDFModel(string base64PDF, TZ_Report_Record record)
        {
            PDFModel model = new PDFModel();
            model.baoGaoBase64 = base64PDF;
            model.tiJianBH = record.physical_no;
            model.jiGouDM = HospitalConfigManager.hospitalBM;
            model.zhengJianHM = record.idcard;
            model.bingRenXM = record.name;
            model.baoGaoSJ = record.report_date;
            model.pdfId = record.pdf_id;

            return model;
        }

        private ResultInfo UpLoad(TZ_Report_Record record)
        {
            ResultInfo res = CodeStatus.success.GetStatus();
            if (record.status == EnumManager.init_code)
            {
                res = DengJi(record);
                if (res.code != CodeStatus.success.GetHashCode())
                    return res;

                res = PDF(record);
                if (res.code != CodeStatus.success.GetHashCode())
                    return res;
            }
            else if (record.status == EnumManager.success_dengji_code)
            {
                res = PDF(record);
                if (res.code != CodeStatus.success.GetHashCode())
                    return res;
            }else
            {
                res = DengJi(record);
                if (res.code != CodeStatus.success.GetHashCode())
                    return res;

                res = PDF(record);
                if (res.code != CodeStatus.success.GetHashCode())
                    return res;
            }

            return res;
        }

        private DengJiModel GetDengJiModel(TZ_Report_Record record)
        {
            DengJiModel model = new DengJiModel();
            model.tiJianBH = record.physical_no;
            model.yuYueSJ = record.register_date;
            model.tiJianSJ = record.physical_date;
            model.bingRenXM = record.name;
            model.xingBie = record.sex_no ?? 9;
            model.nianLing = int.Parse(record.age);
            model.zhengJianHM = record.idcard;
            model.jiGouDM = HospitalConfigManager.hospitalBM;
            model.jiGouMC = HospitalConfigManager.hospitalName;
            model.jiGouDZ = HospitalConfigManager.hospitalAddress;
            model.hunYinZT = record.hunyin_zk;
            model.huaiYun = record.huaiyun_zk;
            model.shouJiHao = record.phone;
            model.youJi = 0;
            model.laiYuan = 4;
            model.sms = 0;
            model.tiJianLX = GetTiJianLX(record.tijianlb, record.danweibm);
            return model;
        }

        private List<TZ_Report_Record> ConvertReportRecord(List<TiJianBModel> listTJBModel)
        {
            List<TZ_Report_Record> listReport = new List<TZ_Report_Record>();
            foreach (TiJianBModel item in listTJBModel)
            {
                TZ_Report_Record record = GetTZ_Report_Record(item);
                listReport.Add(record);
            }

            return listReport;
        }

        private TZ_Report_Record GetTZ_Report_Record(TiJianBModel item)
        {
            TZ_Report_Record record = new TZ_Report_Record();
            record.physical_serial_no = item.TiJianLSH;
            record.physical_no = item.TiJianH;
            record.idcard = StringUtils.ReplaceEmpty(item.ShenFenZH);
            record.phone = StringUtils.ReplaceEmpty(item.ShouJiH);
            record.name = StringUtils.ReplaceEmpty(item.XingMing);
            record.age = item.NianLing;
            record.sex = item.XingBie;
            record.sex_no = GetSexNo(record.sex);
            record.birthday = item.ChuShenRQ;
            record.register_date = ConvertDate(item.DengJiRQ);
            record.physical_date = ConvertDate(item.TiJianRQ);
            if (string.IsNullOrWhiteSpace(item.ZongJianRQ))
                item.ZongJianRQ = item.TiJianRQ;

            record.report_date = ConvertDate(item.ZongJianRQ);
            record.status = EnumManager.init_code;
            record.status_name = EnumManager.init_name;
            record.is_pdf = PDFEnum.init.GetHashCode();
            record.pdf_path = HospitalConfigManager.pdfBaseUrl + "/" + record.physical_no + ".pdf";
            record.hunyin_zk = ConvertHunYinZT(item.HunYinZK);
            record.huaiyun_zk = ConvertHuaiYunZT(string.Empty);
            record.create_time = DateTime.Now;
            record.danweibm = item.DanWeiBM;
            record.tijianlb = item.TiJianLB;

            if (!ToolHelper.IsIDCard(record.idcard))
            {
                VerifyTiJianInfo(record, "身份证号不合法");
            }

            if (!ToolHelper.IsPhone(record.phone))
            {
                VerifyTiJianInfo(record, "手机号不合法");
            }
            record.pdf_id = Guid.NewGuid().ToString();

            return record;
        }

        private ResultInfo Remote(string tjh, string interfaceUrl, string json)
        {
            string result = string.Empty;
            ResultInfo res = Remote(interfaceUrl, json, out result);
            if (res.code != CodeStatus.success.GetHashCode())
                return res;

            res = ResolveResult(tjh, interfaceUrl, result);

            return res;
        }

        /// <summary>
        /// 请求传入接口
        /// </summary>
        /// <param name="interfaceUrl"></param>
        /// <param name="json"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public ResultInfo Remote(string interfaceUrl, string json, out string result)
        {
            result = string.Empty;
            if (string.IsNullOrEmpty(interfaceUrl))
                return CodeStatus.error_201.GetStatus($"{nameof(interfaceUrl)}必传");
            if (string.IsNullOrEmpty(json))
                return CodeStatus.error_201.GetStatus($"{nameof(json)}必传");

            string token = string.Empty;
            ResultInfo res = GetToken(out token);
            if (res.code != CodeStatus.success.GetHashCode())
                return res;

            string remoteUrl = HospitalConfigManager.baseUrl + interfaceUrl;

            IDictionary<string, string> dicHeader = new Dictionary<string, string>();
            dicHeader.Add("Authorization", token);

            result = webUtils.RemotePost(remoteUrl, dicHeader, json, "application/json", "utf-8");

            LogHelper.Warn($"{interfaceUrl}:{result}");
            // 调用成功
            return CodeStatus.success.GetStatus();
        }

        /// <summary>
        /// 获取token
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public ResultInfo GetToken(out string token)
        {
            token = string.Empty;
            // 如果
            object obj = CacherUtils.GetCache(_token);
            if (obj != null)
            {
                token = obj.ToString();
                return CodeStatus.success.GetStatus();
            }

            string remoteUrl = HospitalConfigManager.baseUrl + "/oauth/token";
            IDictionary<string, string> dicHeaders = new Dictionary<string, string>();
            dicHeaders.Add("Authorization", HospitalConfigManager.client);

            IDictionary<string, object> dicParam = new Dictionary<string, object>();
            dicParam.Add("scope", "read");
            dicParam.Add("grant_type", "client_credentials");
            string result = string.Empty;
            try
            {
                result = webUtils.RemotePost(remoteUrl, dicHeaders, dicParam, "application/x-www-form-urlencoded", "utf-8");
                LogHelper.Warn($"token:{result}");
            }
            catch (WebException wex)
            {
                LogHelper.Error($"token:{wex.ToString()}");
                return CodeStatus.error_223.GetStatus(wex.ToString());
            }
            catch (Exception e)
            {
                LogHelper.Error($"token:{e.ToString()}");
                return CodeStatus.error_223.GetStatus(e.ToString());
            }

            string tokenType = string.Empty;
            try
            {
                JObject j = JsonXmlUtils.DeserializeObject<JObject>(result);
                tokenType = "Bearer";
                token = j["value"].ToString();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return CodeStatus.error_223.GetStatus($"获取token失败,{e.ToString()}");
            }

            string AddToken = tokenType + " " + token;

            // 插入缓存
            CacherUtils.InsNoAbsoluteExpirationCacheWithMinute(_token, AddToken, 1320);

            return CodeStatus.success.GetStatus();
        }

        /// <summary>
        /// 解析返回值
        /// </summary>
        /// <param name="result"></param>
        /// <param name="code"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private ResultInfo ResolveResult(string tjh, string interfaceUrl, string result)
        {
            // 返回值
            LogHelper.Info($"{tjh}:{interfaceUrl}:{result}");

            JObject j = null;
            try
            {
                j = JsonXmlUtils.DeserializeObject<JObject>(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return CodeStatus.error_223.GetStatus($"返回值解析失败:{result}");
            }
            string code = string.Empty;
            string msg = string.Empty;
            var jCode = j["code"];
            var jMsg = j["msg"];
            if (jCode != null)
                code = jCode.ToString();
            else
                return CodeStatus.error_203.GetStatus(result);

            if (jMsg != null)
                msg = jMsg.ToString();

            if (code == "1")
                return CodeStatus.success.GetStatus();
            else
                return CodeStatus.error_223.GetStatus(msg);
        }

        private string ConvertDate(string date)
        {

            DateTime dt = DateTime.Now;
            if (!string.IsNullOrEmpty(date))
            {
                try
                {
                    dt = DateTime.Parse(date);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            return dt.ToString(formatTime);
        }

        private int GetSexNo(string xingBie)
        {
            if (string.IsNullOrEmpty(xingBie))
                return 9;

            int sexNo = 0;
            if (xingBie == "男")
                sexNo = 1;
            else if (xingBie == "女")
                sexNo = 2;

            return sexNo;
        }

        private int ConvertHuaiYunZT(string hyzt)
        {
            int hyztBM = 0;
            if (!string.IsNullOrEmpty(hyzt))
                hyztBM = 1;

            return hyztBM;
        }

        private int ConvertHunYinZT(string hyzk)
        {
            int hyzkBM = 0;
            if (!string.IsNullOrEmpty(hyzk) && hyzk.Contains("已"))
                hyzkBM = 1;

            return hyzkBM;
        }

        private string GetTiJianLX(string tiJianLB, string danweiBM)
        {
            string result = "0";
            if (!string.IsNullOrEmpty(tiJianLB) && tiJianLB.Contains("职业"))
            {
                result = "2";
                return result;
            }

            if (!string.IsNullOrEmpty(danweiBM))
                result = "1";

            return result;
        }

        private void VerifyTiJianInfo(TZ_Report_Record record, string failMsg)
        {
            record.status = EnumManager.fail_info_code;
            record.status_name = EnumManager.fail_info_name;
            record.fail_msg = failMsg;
        }
    }
}
